package com.ego.controller;

import com.ego.pojo.ItemCategoryNav;
import com.ego.pojo.TbItemDetails;
import com.ego.service.ItemCatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/**
 * @Title
 * @Author Lyg
 * @Description:
 */
@Controller
public class ItemController {

    @Autowired
    private ItemCatService itemCatService;

    @RequestMapping("/rest/itemcat/all")
    @ResponseBody
    @CrossOrigin //开启跨域远程访问   //支持跨域请求
    public ItemCategoryNav showItemCat(){
        return itemCatService.showItemCat();
    }

    @RequestMapping("/item/{id}.html")
    public String itemDetail(@PathVariable Long id, Model model){
        System.out.println("id = " + id);
        TbItemDetails tbItemDetail = itemCatService.selectById(id);
        model.addAttribute("item", tbItemDetail);
        return "item";
    }
    //查询商品描述
    @GetMapping("item/desc/{id}.html")
    @ResponseBody
    public  String itemDesc(@PathVariable Long id){
        String itemDesc = itemCatService.selectItemDescByItemId(id);
        return itemDesc;
    }
    //查询商品规格参数
@GetMapping("/item/param/{id}.html")
@ResponseBody
    public String itemParam(@PathVariable Long id){
    String itemParm = itemCatService.selectItemParamByItemId(id);

    return itemParm;
}

}
